﻿//Test by Bangle
using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Bangle.DBUtility;
namespace Bangle.DAL
{
    //T_ProgressRecord
    public partial class T_ProgressRecordDAL
    {

        public bool Exists(Guid ProgressRecordId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_ProgressRecord");
            strSql.Append(" where ");
            strSql.Append(" ProgressRecordId = @ProgressRecordId  ");
            SqlParameter[] parameters = {
					new SqlParameter("@ProgressRecordId", SqlDbType.UniqueIdentifier,16)			};
            parameters[0].Value = ProgressRecordId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Bangle.Model.T_ProgressRecord model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_ProgressRecord(");
            strSql.Append("ProgressRecordId,CustomerId,RecordTypeId,ProgressTypeId,RecordTime,RecordContent,CreateTime,CreateUserId,UpdateTime,UpdateUserId,Valid,NextRecordTime,NextRecordContent,NextRecordRead");
            strSql.Append(") values (");
            strSql.Append("@ProgressRecordId,@CustomerId,@RecordTypeId,@ProgressTypeId,@RecordTime,@RecordContent,@CreateTime,@CreateUserId,@UpdateTime,@UpdateUserId,@Valid,@NextRecordTime,@NextRecordContent,@NextRecordRead");
            strSql.Append(") ");

            SqlParameter[] parameters = {
			            new SqlParameter("@ProgressRecordId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@RecordTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ProgressTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RecordTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@RecordContent", SqlDbType.VarChar,8000) ,            
                        new SqlParameter("@CreateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@CreateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@UpdateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Valid", SqlDbType.Int,4) ,            
                        new SqlParameter("@NextRecordTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@NextRecordContent", SqlDbType.VarChar,1000) ,            
                        new SqlParameter("@NextRecordRead", SqlDbType.Int,4)             
              
            };

            parameters[0].Value = model.ProgressRecordId;
            parameters[1].Value = model.CustomerId;
            parameters[2].Value = model.RecordTypeId;
            parameters[3].Value = model.ProgressTypeId;
            parameters[4].Value = model.RecordTime;
            parameters[5].Value = model.RecordContent;
            parameters[6].Value = model.CreateTime;
            parameters[7].Value = model.CreateUserId;
            parameters[8].Value = model.UpdateTime;
            parameters[9].Value = model.UpdateUserId;
            parameters[10].Value = model.Valid;
            parameters[11].Value = model.NextRecordTime;
            parameters[12].Value = model.NextRecordContent;
            parameters[13].Value = model.NextRecordRead;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Bangle.Model.T_ProgressRecord model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_ProgressRecord set ");

            strSql.Append(" ProgressRecordId = @ProgressRecordId , ");
            strSql.Append(" CustomerId = @CustomerId , ");
            strSql.Append(" RecordTypeId = @RecordTypeId , ");
            strSql.Append(" ProgressTypeId = @ProgressTypeId , ");
            strSql.Append(" RecordTime = @RecordTime , ");
            strSql.Append(" RecordContent = @RecordContent , ");
            strSql.Append(" CreateTime = @CreateTime , ");
            strSql.Append(" CreateUserId = @CreateUserId , ");
            strSql.Append(" UpdateTime = @UpdateTime , ");
            strSql.Append(" UpdateUserId = @UpdateUserId , ");
            strSql.Append(" Valid = @Valid , ");
            strSql.Append(" NextRecordTime = @NextRecordTime , ");
            strSql.Append(" NextRecordContent = @NextRecordContent , ");
            strSql.Append(" NextRecordRead = @NextRecordRead  ");
            strSql.Append(" where ProgressRecordId=@ProgressRecordId  ");

            SqlParameter[] parameters = {
			            new SqlParameter("@ProgressRecordId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@RecordTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ProgressTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RecordTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@RecordContent", SqlDbType.VarChar,8000) ,            
                        new SqlParameter("@CreateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@CreateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@UpdateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Valid", SqlDbType.Int,4) ,            
                        new SqlParameter("@NextRecordTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@NextRecordContent", SqlDbType.VarChar,1000) ,            
                        new SqlParameter("@NextRecordRead", SqlDbType.Int,4)             
              
            };

            parameters[0].Value = model.ProgressRecordId;
            parameters[1].Value = model.CustomerId;
            parameters[2].Value = model.RecordTypeId;
            parameters[3].Value = model.ProgressTypeId;
            parameters[4].Value = model.RecordTime;
            parameters[5].Value = model.RecordContent;
            parameters[6].Value = model.CreateTime;
            parameters[7].Value = model.CreateUserId;
            parameters[8].Value = model.UpdateTime;
            parameters[9].Value = model.UpdateUserId;
            parameters[10].Value = model.Valid;
            parameters[11].Value = model.NextRecordTime;
            parameters[12].Value = model.NextRecordContent;
            parameters[13].Value = model.NextRecordRead;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid ProgressRecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_ProgressRecord ");
            strSql.Append(" where ProgressRecordId=@ProgressRecordId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ProgressRecordId", SqlDbType.UniqueIdentifier,16)			};
            parameters[0].Value = ProgressRecordId;


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Bangle.Model.T_ProgressRecord GetModel(Guid ProgressRecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ProgressRecordId, CustomerId, RecordTypeId, ProgressTypeId, RecordTime, RecordContent, CreateTime, CreateUserId, UpdateTime, UpdateUserId, Valid, NextRecordTime, NextRecordContent, NextRecordRead  ");
            strSql.Append("  from T_ProgressRecord ");
            strSql.Append(" where ProgressRecordId=@ProgressRecordId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ProgressRecordId", SqlDbType.UniqueIdentifier,16)			};
            parameters[0].Value = ProgressRecordId;


            Bangle.Model.T_ProgressRecord model = new Bangle.Model.T_ProgressRecord();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ProgressRecordId"].ToString() != "")
                {
                    model.ProgressRecordId = Guid.Parse(ds.Tables[0].Rows[0]["ProgressRecordId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomerId"].ToString() != "")
                {
                    model.CustomerId = Guid.Parse(ds.Tables[0].Rows[0]["CustomerId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RecordTypeId"].ToString() != "")
                {
                    model.RecordTypeId = int.Parse(ds.Tables[0].Rows[0]["RecordTypeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProgressTypeId"].ToString() != "")
                {
                    model.ProgressTypeId = int.Parse(ds.Tables[0].Rows[0]["ProgressTypeId"].ToString());
                }
                model.RecordTime = ds.Tables[0].Rows[0]["RecordTime"].ToString();
                model.RecordContent = ds.Tables[0].Rows[0]["RecordContent"].ToString();
                model.CreateTime = ds.Tables[0].Rows[0]["CreateTime"].ToString();
                if (ds.Tables[0].Rows[0]["CreateUserId"].ToString() != "")
                {
                    model.CreateUserId = int.Parse(ds.Tables[0].Rows[0]["CreateUserId"].ToString());
                }
                model.UpdateTime = ds.Tables[0].Rows[0]["UpdateTime"].ToString();
                if (ds.Tables[0].Rows[0]["UpdateUserId"].ToString() != "")
                {
                    model.UpdateUserId = int.Parse(ds.Tables[0].Rows[0]["UpdateUserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Valid"].ToString() != "")
                {
                    model.Valid = int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
                }
                model.NextRecordTime = ds.Tables[0].Rows[0]["NextRecordTime"].ToString();
                model.NextRecordContent = ds.Tables[0].Rows[0]["NextRecordContent"].ToString();
                if (ds.Tables[0].Rows[0]["NextRecordRead"].ToString() != "")
                {
                    model.NextRecordRead = int.Parse(ds.Tables[0].Rows[0]["NextRecordRead"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_ProgressRecord ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM T_ProgressRecord ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


    }
}

